package exchange.util;

import java.util.LinkedList;

public class Order implements Comparable<Order>{
	private Client client; 
	private int orderId;
	private Stock stock;
	private OrderType orderType;
	private float price;
	private int amount;
	
	public Order(Client client, int orderId, Stock stock, OrderType orderType, float price, int amount) {
		this.client = client;
		this.orderId = orderId;
		this.stock = stock;
		this.orderType = orderType;
		this.price = price;
		this.amount = amount;
	}

	@Override
	public int compareTo(Order order) {
		return (int)(this.price - order.price);
	}

	public boolean isCounterpartyPriceIsEqualOrBetter(Order anotherOrder){
		boolean result;
		
		if ( anotherOrder.getPrice() >= this.getPrice() && this.isBid()  ){
			result = true;
		} else if ( anotherOrder.getPrice() <= this.getPrice() && this.isAsk()  ) {
			result = true;
		} else {
			result = false;
		}
		
		return result; 
	}

	@Override
	public String toString() {
		return ("Client: " + client.getName() + " id " + orderId +
				" Stock: " + stock.getName() + " OrderType " + orderType.getType() +
				" Price: " + price + " Amount: " + amount );
	}

	
	public Client getClient() {
		return client;
	}

	public int getOrderId() {
		return orderId;
	}

	public Stock getStock() {
		return stock;
	}
	
	public OrderType getOrderType() {
		return orderType;
	}

	public float getPrice() {
		return price;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;	
	}

	public LinkedList<Order> getCounterpartyList() {
		return isBid() ? getStock().getAskList() : getStock().getBidList();
	}

	public LinkedList<Order> getList() {
		return isBid() ? getStock().getBidList() : getStock().getAskList();
	}

	public boolean isBid() {
		if (this.orderType == OrderType.BID){
			return true;
		} else {
			return false;
		}
	}
	
	public boolean isAsk() {
		if (this.orderType == OrderType.ASK){
			return true;
		} else {
			return false;
		}
	}
	
	public boolean isFullFilled(){
		if(amount > 0) {
			return false;
		} else {
			return true;
		}
	}
	
}
